home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / FDF101.ARJ / FDFSTAT.C < prev    next >
C/C++ Source or Header  |  1992-04-29  |  3KB  |  135 lines

  1. /*
  2.  * fdstat.c
  3.  *
  4.  * maintain, compute and print out statistics on duplicate files.
  5.  *
  6.  * Roy Bixler
  7.  * March 29, 1991
  8.  *
  9.  * This program is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 1, or (at your option)
  12.  * any later version.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this program; if not, write to the Free Software
  21.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  */
  23.  
  24.  
  25.  
  26. #include <dir.h>
  27. #include <dos.h>
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30.  
  31. #include "fdfcomm.h"
  32. #include "fdfstat.h"
  33.  
  34.  
  35.  
  36. static unsigned long total_bytes = 0UL, total_dup_bytes = 0UL;
  37. static unsigned long total_del_bytes = 0UL;
  38. static unsigned int num_files = 0U, num_which_dupd = 0U, num_dups = 0U;
  39.  
  40.  
  41.  
  42. /*
  43.  * update_total_bytes
  44.  *
  45.  * called to update the total number of bytes in duplicate files
  46.  */
  47. void update_total_bytes(long f_size)
  48.  
  49. {
  50.     total_bytes += f_size;
  51. }
  52.  
  53.  
  54.  
  55. /*
  56.  * update_total_del_bytes
  57.  *
  58.  * called to update the total number of bytes in duplicate files
  59.  */
  60. void update_total_del_bytes(long f_size)
  61.  
  62. {
  63.     total_del_bytes += f_size;
  64. }
  65.  
  66.  
  67.  
  68. /*
  69.  * update_num_files
  70.  *
  71.  * called to update the total number of files
  72.  */
  73. void update_num_files()
  74.  
  75. {
  76.     num_files++;
  77. }
  78.  
  79.  
  80.  
  81. /*
  82.  * update_num_which_dupd
  83.  *
  84.  * called to update the total number of files which have duplicates
  85.  */
  86. void update_num_which_dupd()
  87.  
  88. {
  89.     num_which_dupd++;
  90. }
  91.  
  92.  
  93.  
  94. /*
  95.  * update_num_dups
  96.  *
  97.  * called to update the total number of duplicate files and total bytes in same
  98.  */
  99. void update_num_dups(unsigned n_dups, long bytes)
  100.  
  101. {
  102.     num_dups += n_dups;
  103.     total_dup_bytes += bytes;
  104. }
  105.  
  106.  
  107.  
  108. /*
  109.  * print_stats
  110.  *
  111.  * tabulate the statistics for this run of 'find duplicates'
  112.  */
  113. void print_stats()
  114.  
  115. {
  116.     printf("Total # of files = %u\n", num_files);
  117.     printf("Total bytes in files = %lu\n\n", total_bytes);
  118.  
  119.     printf("Total # of duplicate file names = %u\n", num_which_dupd);
  120.     printf("Total # of duplicate files = %u\n", num_dups);
  121.     printf("Total bytes in duplicate files = %lu\n", total_dup_bytes);
  122.     if (i_flag)
  123.         printf("Total bytes deleted = %lu\n", total_del_bytes);
  124.     if (num_dups > 0)
  125.         printf("\nAverage duplicate file size = %ld", total_dup_bytes/num_dups);
  126.     if ((num_files > 0) && (num_dups > 0))
  127.         printf("\nAverage # of duplicates per file = %f",
  128.                (float) num_dups/num_files);
  129.     if ((num_which_dupd > 0) && (num_dups > 0))
  130.         printf("\nAverage # of duplicates per duplicate name = %f",
  131.                (float) num_dups/num_which_dupd);
  132.     if (num_dups)
  133.         printf("\n");
  134. }
  135.